#ifndef UI_LAYERWIDGET_H
#define UI_LAYERWIDGET_H

#include <qwidget.h>
#include <q3listbox.h>
//Added by qt3to4:
#include <QPixmap>
#include <QContextMenuEvent>
#include <QKeyEvent>

#include "pf_layerlist.h"
#include "pf_layerlistobserver.h"

#include "wf_actionhandler.h"
#include "gui_export.h"



/**
 * This is the Qt implementation of a widget which can view a 
 * layer list and provides a user interface for basic layer actions.
 */
class GUI_EXPORT UI_LayerWidget: public QWidget, public PF_LayerListObserver {
    Q_OBJECT

public:
    UI_LayerWidget(WF_ActionHandler* ah, QWidget* parent,
                   const char* name=0, Qt::WFlags f = 0);
    ~UI_LayerWidget();

    void setLayerList(PF_LayerList* layerList, bool showByBlock);

    void update();
    void highlightLayer(PF_Layer* layer);
    void highlightLayer(const QString& name);

    virtual void layerActivated(PF_Layer* layer) {
        highlightLayer(layer);
    }
    virtual void layerAdded(PF_Layer* layer) {
        update();
        highlightLayer(layer);
    }
    virtual void layerEdited(PF_Layer*) {
        update();
    }
    virtual void layerRemoved(PF_Layer*) {
        update();
        highlightLayer(layerList->at(0));
    }
    virtual void layerToggled(PF_Layer*) {
        update();
    }

signals:
	void escape();

public slots:
    void slotActivated(const QString& layerName);
	void slotMouseButtonClicked(int button, Q3ListBoxItem* item, 
		const QPoint& pos);

protected:
    void contextMenuEvent(QContextMenuEvent *e);
	virtual void keyPressEvent(QKeyEvent* e);

private:
    PF_LayerList* layerList;
    bool showByBlock;
    Q3ListBox* listBox;
	PF_Layer* lastLayer;
    QPixmap pxmLayerStatus00;
    QPixmap pxmLayerStatus01;
    QPixmap pxmLayerStatus10;
    QPixmap pxmLayerStatus11;
    QPixmap pxmVisible;
    QPixmap pxmHidden;
    QPixmap pxmAdd;
    QPixmap pxmRemove;
    QPixmap pxmEdit;
    QPixmap pxmDefreezeAll;
    QPixmap pxmFreezeAll;
    WF_ActionHandler* actionHandler;
};

#endif
